Page({
  data: {
    // 当前页
    current: 1,
    // 每页大小
    pageSize: 3,
    // 总页数
    pageTotal: 0,
    // 总条数
    total: 0,
    visitorList: [],
    // 节流阀
    isLoading: true,
  },
  goPassport(e) {
    const id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/visitor_pkg/pages/passport/index?id=${id}`,
    })
  },

  /* 获取房客列表 */
  async getVisitorList() {
    const {
      data
    } = await wx.http.get('/visitor', {
      current: this.data.current + '',
      pageSize: this.data.pageSize + '',
    })
    this.setData({
      total: data.total,
      pageTotal: data.pageTotal,
      visitorList: [...this.data.visitorList, ...data.rows],
    })

  },
  async refreshVisitor() {
    if (this.data.current * this.data.pageSize < this.data.total) {
      this.setData({
        current: this.data.current + 1
      })
      await this.getVisitorList()
    }
  },

  async onLoad() {
    await this.getVisitorList()
  },

  /* 上拉触底加载房客列表 */
  onReachBottom() {},
})